package top.crossrun.webview.bridge.plugin.common;

import android.content.SharedPreferences;

import org.json.JSONObject;

import top.crossrun.webview.bridge.core.pls.BridgeCallBackFunction;
import top.crossrun.webview.bridge.core.pls.WebViewBridgePlugin;

/**
 * create by Run
 * on 2020/10/13 14:30
 * do
 */
public class GetSpference extends WebViewBridgePlugin {
    @Override
    public void handlerBridgeMsg(String msg, BridgeCallBackFunction callBackFunction) {
        try {
            JSONObject json = new JSONObject(new JSONObject(msg).getString("params"));
            String var1 = json.getString("key");
            SharedPreferences sp = getContext().getSharedPreferences(var1, 0);
            var1 = sp.getString(var1, "");
            JSONObject var5;
            (var5 = new JSONObject()).put("value", var1);
            JSONObject var4;
            (var4 = new JSONObject()).put("data", var5);
            callBackFunction.onCallBackFunction(var4.toString());
        } catch (Exception e) {
            e.printStackTrace();
//            Toast.makeText(getContext(), "参数错误！1", Toast.LENGTH_LONG).show();
        }
    }

    @Override
    public String getPluginName() {
        return "getSpference";
    }
}
